package com.itheima.controller;

import com.itheima.pojo.User;
import org.springframework.context.annotation.Configuration;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.xml.crypto.Data;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;

@Configuration
@RequestMapping("/param")
public class ParamController {

   /*
    //1. 请求对象接收参数
    @ResponseBody
    @RequestMapping("/req1")
    public String param1(HttpServletRequest request){
        System.out.println(request.getParameter("username"));
        return "{'info' : 'ok'}";
    }*/


    /*
    //2. 变量接收
    @ResponseBody
    @RequestMapping("/req2")
    public String param2(String username){
        System.out.println("username=" + username);
        return "{'info' : 'ok'}";
    }*/


   /*//3. 注解起别名@RequestParam
    @ResponseBody
    @RequestMapping("/req3")
    public String param3(@RequestParam(value = "user",required = false,defaultValue = "咋了")
                                     String username , String age){
        System.out.println("username=" + username);
        System.out.println("age=" + age);
        return "{'info' : 'ok'}";
    }*/


/*
    //4. pojo set方法，自动匹配属性
    @ResponseBody
    @RequestMapping("/req4")
    public String param4(User user) {
        System.out.println(user);
        return "{'info' : 'ok'}";
    }*/


/*

    //5. 按照集合方式接收  list  需要@RequestParam
    @ResponseBody
    @RequestMapping("/req5")
    public String param5(@RequestParam List<String> list) {
        System.out.println(list);
        return "{'info' : 'ok'}";
    }
*/


    /*@ResponseBody
    @RequestMapping("/req6")
    public String param6(@RequestParam Map map) {
        System.out.println(map);
        return "{'info' : 'ok'}";
    }*/
/*
    @ResponseBody
    @RequestMapping("/req7")
    public String param7(String[] strs) {
        System.out.println(Arrays.toString(strs));
        return "{'info' : 'ok'}";
    }*/

    //6. 日期类型
    @ResponseBody
    @RequestMapping("/req8")
    public String param8(Date date   //默认接收的是2088/08/18
                ,@DateTimeFormat(pattern = "yyyy-MM-dd") Date date1  //指定格式的字符串转换日期
                ,@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date date2 //指定格式的字符串转换日期
         ) {
        System.out.println(date);
        System.out.println(date1);
        System.out.println(date2);
        return "{'info' : 'ok'}";
    }
}
